package com.ruoyi.web.controller.swimming;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swimming.domian.MallCustomerAddress;
import com.ruoyi.swimming.service.IMallCustomerAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 快递地址Controller
 * 
 * @author ruoyi
 * @date 2021-07-17
 */
@RestController
@RequestMapping("/system/address")
public class MallCustomerAddressController extends BaseController
{
    @Autowired
    private IMallCustomerAddressService mallCustomerAddressService;

    /**
     * 查询快递地址列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:list')")
    @GetMapping("/list")
    public TableDataInfo list(MallCustomerAddress mallCustomerAddress)
    {
        startPage();
        List<MallCustomerAddress> list = mallCustomerAddressService.selectMallCustomerAddressList(mallCustomerAddress);
        return getDataTable(list);
    }

    /**
     * 导出快递地址列表
     */
    @PreAuthorize("@ss.hasPermi('system:address:export')")
    @Log(title = "快递地址", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MallCustomerAddress mallCustomerAddress)
    {
        List<MallCustomerAddress> list = mallCustomerAddressService.selectMallCustomerAddressList(mallCustomerAddress);
        ExcelUtil<MallCustomerAddress> util = new ExcelUtil<MallCustomerAddress>(MallCustomerAddress.class);
        return util.exportExcel(list, "快递地址数据");
    }

    /**
     * 获取快递地址详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:address:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mallCustomerAddressService.selectMallCustomerAddressById(id));
    }

    /**
     * 新增快递地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:add')")
    @Log(title = "快递地址", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MallCustomerAddress mallCustomerAddress)
    {
        return toAjax(mallCustomerAddressService.insertMallCustomerAddress(mallCustomerAddress));
    }

    /**
     * 修改快递地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:edit')")
    @Log(title = "快递地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MallCustomerAddress mallCustomerAddress)
    {
        return toAjax(mallCustomerAddressService.updateMallCustomerAddress(mallCustomerAddress));
    }

    /**
     * 删除快递地址
     */
    @PreAuthorize("@ss.hasPermi('system:address:remove')")
    @Log(title = "快递地址", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mallCustomerAddressService.deleteMallCustomerAddressByIds(ids));
    }
}
